package time.compiler.query;
import time.compiler.types.Data;

/**
 * All query-related (1st pass) data types
 * 
 * @author waneck
 */

typedef QueryExpr =
{
	pos : haxe.macro.Expr.Position,
	expr : QueryExprDef,
	t : DBType
}

typedef ParsedQuery = 
{
	expr:QueryExpr,
}

//this is only here so we can extend later on to support partial queries
enum QueryEntryPoint
{
	EPClass(cl:String);
}

enum QueryExprDef
{
	QVar(name:String, expr:QueryExpr);
	QDescend(expr:QueryExpr, field:String, mk:MemberKind); //field
	QBinop(op:QueryOp, e1:QueryExpr, e2:QueryExpr);
	QUnop(op:QueryUnop, e:QueryExpr);
	QCall(e1:QueryExpr, s:String, ecall:Array<QueryExpr>, solver:Null<String>);
	QBuiltin(op:BuiltinOp, ecall:Array<QueryExpr>);
	QConst(c:QueryConst);
	QBlock(a:Array<QueryExpr>);
	QPar(e:QueryExpr);
	QFunction(f:QueryFunction);
	QSelect(entryPoint:QueryEntryPoint);
}

typedef QueryFunction =
{
	args : Array <QFunctionArg>,
	ret : DBType,
	expr : QueryExpr
}

typedef QFunctionArg = 
{
	name : String,
	t : DBType
	
}

enum BuiltinOp
{
	BIs;
	BCast;
	BEnumName;
	//BParent; //parent() -> for parent/child relations TODO: support this on DefaultSolver
}

enum QueryUnop
{
	QOpNeg;
	QOpNot;
}

enum QueryOp
{
	QOpAdd;
	QOpMult;
	QOpDiv;
	QOpSub;
	QOpEq;
	QOpNotEq;
	QOpGt;
	QOpGte;
	QOpLt;
	QOpLte;
	QOpBoolAnd;
	QOpBoolOr;
	QOpMod;
}

enum QueryConst
{
	QCExternalVar(name:String);
	QCVar(name:String);
	QCInt(i:Int);
	QCFloat(f:Float);
	QCString(s:String);
	QCBool(b:Bool);
	//TODO QCArray(arr:Array<QueryConst>);
	QCType(typePath:String);
	QCNull;
}